import json
import pymysql

with open('salary.json') as f:
    contents = json.loads(f.read())
    datas = contents['data']
    i=0
for data in datas:
    a = [data.get('1')][0].split(',')+[data.get('3')]
    conn = pymysql.connect(host="localhost", user="root",
                           password="root", db="nba", port=3306, charset='utf8')
    # 使用cursor()方法获取操作游标
    cur = conn.cursor()
    # 编写sql语句
    sql = "INSERT INTO player_info(displayNameEn,positionEN,salary) VALUES (%s,%s,%s)"
    effect = cur.execute(sql, a)
    conn.commit()
print('添加数据库成功！')
# 关闭游标
cur.close()
# 关闭连接
conn.close()